#include "stdafx.h"
#include "net/RawSocketImpl.hpp"

NET_NAMESPACE_BEGIN

CRawSocketImpl::CRawSocketImpl()
{
	init(AF_INET);
}

CRawSocketImpl::CRawSocketImpl(CIPAddress::Family family, int proto)
{
	if (family == CIPAddress::IPv4)
		init2(AF_INET, proto);
#if defined(JH_HAVE_IPv6)
	else if (family == CIPAddress::IPv6)
		init2(AF_INET6, proto);
#endif
	else 
		throw InvalidArgumentException("Invalid or unsupported address family passed to RawSocketImpl");

}

CRawSocketImpl::CRawSocketImpl(JH_SOCKET sockfd) : CSocketImpl(sockfd)
{
}

CRawSocketImpl::~CRawSocketImpl()
{
}

void CRawSocketImpl::init(int af)
{
	init2(af, IPPROTO_RAW);
}

void CRawSocketImpl::init2(int af, int proto)
{
	initSocket(af, SOCK_RAW, proto);
	setOption(IPPROTO_IP, IP_HDRINCL, 0);
}

NET_NAMESPACE_END
